Changing comments layout preparing for generated documentation with Phpdocumentor
[lhc/web/wiklou.git] / includes / SpecialAllmessages.php
1 <?php
2 /**
3 * Provide functions to generate a special page
4 */
5
6 /**
7 *
8 */
9 function wfSpecialAllmessages() {
10 global $wgOut, $wgAllMessagesEn, $wgRequest, $wgMessageCache, $wgTitle;
11
12 $fname = "wfSpecialAllMessages";
13 wfProfileIn( $fname );
14
15 wfProfileIn( "$fname-setup");
16 $ot = $wgRequest->getText( 'ot' );
17 $mwMsg =& MagicWord::get( MAG_MSG );
18
19 $navText = wfMsg( 'allmessagestext', $mwMsg->getSynonym( 0 ) );
20 $first = true;
21 $sortedArray = $wgAllMessagesEn;
22 ksort( $sortedArray );
23 $messages = array();
24 $wgMessageCache->disableTransform();
25 foreach ( $sortedArray as $key => $enMsg ) {
26 $messages[$key]['enmsg'] = $enMsg;
27 $messages[$key]['statmsg'] = wfMsgNoDb( $key );
28 $messages[$key]['msg'] = wfMsg ( $key );
29 }
30 wfProfileOut( "$fname-setup" );
31
32 wfProfileIn( "$fname-output" );
33 if ($ot == 'php') {
34 $navText .= makePhp($messages);
35 $wgOut->addHTML('PHP | <a href="'.$wgTitle->escapeLocalUrl('ot=html').'">HTML</a><pre>'.htmlspecialchars($navText).'</pre>');
36 } else {
37 $wgOut->addHTML( '<a href="'.$wgTitle->escapeLocalUrl('ot=php').'">PHP</a> | HTML' );
38 $wgOut->addWikiText( $navText );
39 $wgOut->addHTML( makeHTMLText( $messages ) );
40 }
41 wfProfileOut( "$fname-output" );
42
43 wfProfileOut( $fname );
44 }
45
46 /**
47 *
48 */
49 function makePhp($messages) {
50 global $wgLanguageCode;
51 $txt = "\n\n".'$wgAllMessages'.ucfirst($wgLanguageCode).' = array('."\n";
52 foreach( $messages as $key => $m ) {
53 if(strtolower($wgLanguageCode) != 'en' and $m['msg'] == $m['enmsg'] ) {
54 if (strstr($m['msg'],"\n")) {
55 $txt.='/* ';
56 $comment=' */';
57 } else {
58 $txt .= '#';
59 $comment = '';
60 }
61 } elseif ($m['msg'] == '&lt;'.$key.'&gt;'){
62 $m['msg'] = '';
63 $comment = ' #empty';
64 } else {
65 $comment = '';
66 }
67 $txt .= "'".$key."' => \"".str_replace('"','\"',$m['msg'])."\",$comment\n";
68 }
69 $txt .= ');';
70 return $txt;
71 }
72
73 /**
74 *
75 */
76 function makeHTMLText( $messages ) {
77 global $wgLang, $wgUser;
78 $fname = "makeHTMLText";
79 wfProfileIn( $fname );
80
81 $sk =& $wgUser->getSkin();
82 $talk = $wgLang->getNsText( NS_TALK );
83 $mwnspace = $wgLang->getNsText( NS_MEDIAWIKI );
84 $mwtalk = $wgLang->getNsText( NS_MEDIAWIKI_TALK );
85 $txt = "
86
87 <table border='1' cellspacing='0' width='100%'>
88 <tr bgcolor='#b2b2ff'>
89 <th>Name</th>
90 <th>Default text</th>
91 <th>Current text</th>
92 </tr>";
93
94 wfProfileIn( "$fname-check" );
95 # This is a nasty hack to avoid doing independent existence checks
96 # without sending the links and table through the slow wiki parser.
97 $pageExists = array(
98 NS_MEDIAWIKI => array(),
99 NS_MEDIAWIKI_TALK => array()
100 );
101 $sql = "SELECT cur_namespace,cur_title FROM cur WHERE cur_namespace IN (" . NS_MEDIAWIKI . ", " . NS_MEDIAWIKI_TALK . ")";
102 $dbr =& wfGetDB( DB_SLAVE );
103 $res = $dbr->query( $sql );
104 while( $s = $dbr->fetchObject( $res ) ) {
105 $pageExists[$s->cur_namespace][$s->cur_title] = true;
106 }
107 $dbr->freeResult( $res );
108 wfProfileOut( "$fname-check" );
109
110 wfProfileIn( "$fname-output" );
111 foreach( $messages as $key => $m ) {
112 $title = $wgLang->ucfirst( $key );
113 $titleObj =& Title::makeTitle( NS_MEDIAWIKI, $title );
114 $talkPage =& Title::makeTitle( NS_MEDIAWIKI_TALK, $title );
115
116 $colorIt = ($m['statmsg'] == $m['msg']) ? " bgcolor=\"#f0f0ff\"" : " bgcolor=\"#ffe2e2\"";
117 $message = htmlspecialchars( $m['statmsg'] );
118 $mw = htmlspecialchars( $m['msg'] );
119
120 #$pageLink = $sk->makeLinkObj( $titleObj, htmlspecialchars( $key ) );
121 #$talkLink = $sk->makeLinkObj( $talkPage, htmlspecialchars( $talk ) );
122 if( isset( $pageExists[NS_MEDIAWIKI][$title] ) ) {
123 $pageLink = $sk->makeKnownLinkObj( $titleObj, htmlspecialchars( $key ) );
124 } else {
125 $pageLink = $sk->makeBrokenLinkObj( $titleObj, htmlspecialchars( $key ) );
126 }
127 if( isset( $pageExists[NS_MEDIAWIKI_TALK][$title] ) ) {
128 $talkLink = $sk->makeKnownLinkObj( $talkPage, htmlspecialchars( $talk ) );
129 } else {
130 $talkLink = $sk->makeBrokenLinkObj( $talkPage, htmlspecialchars( $talk ) );
131 }
132
133 $txt .=
134 "<tr$colorIt><td>
135 $pageLink<br />
136 $talkLink
137 </td><td>
138 $message
139 </td><td>
140 $mw
141 </td></tr>";
142 }
143 $txt .= "</table>";
144 wfProfileOut( "$fname-output" );
145
146 wfProfileOut( $fname );
147 return $txt;
148 }
149
150 ?>